package com.openjaw.lsy.agent.SPMClientThread;

import com.openjaw.lsy.agent.business.xdist.enums.XDistributorFrameType;
import com.openjaw.lsy.agent.business.xdist.monitor.MonitorCommon;
import com.openjaw.lsy.agent.core.logging.api.ILog;
import com.openjaw.lsy.agent.core.logging.api.LogManager;
import com.openjaw.lsy.agent.core.plugin.intercept.enhance.InstanceMethodsAroundInterceptor;
import com.openjaw.lsy.agent.core.plugin.intercept.enhance.MethodInterceptResult;
import java.lang.reflect.Method;

public class ClientInterceptor implements InstanceMethodsAroundInterceptor {

    private static final ILog logger = LogManager.getLogger(ClientInterceptor.class);

    @Override public void beforeMethod(Object objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
        MethodInterceptResult result) throws Throwable {
        com.openjaw.serviceProvider.SPMProcessingState state = (com.openjaw.serviceProvider.SPMProcessingState)allArguments[0];
        MonitorCommon.monitor("Client_" + state.getNode().getCode(), state.getRequest().getMessageName(), XDistributorFrameType.Client);

    }

    @Override public Object afterMethod(Object objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
        Object ret) throws Throwable {
        com.openjaw.serviceProvider.SPMProcessingState state = (com.openjaw.serviceProvider.SPMProcessingState)allArguments[0];
        MonitorCommon.monitorStop("Client_" + state.getNode().getCode(), state.getRequest().getMessageName(), XDistributorFrameType.Client);
        return ret;
    }

    @Override
    public void handleMethodException(Object objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
        Throwable t) {

    }
}
